package com.shadowtorcher.dragonstreasure.controller;

import com.shadowtorcher.dragonstreasure.filelogic.StaticFileLogic;
import com.shadowtorcher.dragonstreasure.url.DownloadURL;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;


@RestController
public class CheckUrlController {
    @RequestMapping(value = "/check/{uuid}/{username}/{time}/{check_code}/{file_name}", method = RequestMethod.POST)
    public void check(@PathVariable("uuid") String uuid, @PathVariable("username") String username,
                      @PathVariable("time") String time, @PathVariable("check_code") String check_code,
                      @PathVariable String file_name, HttpServletResponse response) {
        DownloadURL downloadURL = new DownloadURL();
        downloadURL.setUUID(uuid);
        downloadURL.setUsername(username);
        downloadURL.setTime(time);
        downloadURL.setCheckCode(check_code);
        downloadURL.setFileName(file_name);
        if (!StaticFileLogic.checkFileURL(downloadURL)) {
            response.setStatus(403);
        } else {
            response.setStatus(200);
        }
    }
}
